package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.OrdersDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import com.sky.vo.OrderVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;


@Mapper
public interface  OrderMapper  {

        /**
     * 根据用户ID查询
     *
     * @param order
     */
    public void insert(Orders order);
    @Select("select * from orders where user_id = #{userId} order by order_time desc")
    Page<OrderVO> getUserId(Long userId);

    /**
     * 根据ID查询数据
     * @param id
     * @return
     */
    @Select("select * from orders where id =#{id}")
    OrderVO getById(Long id);

    /**
     * 修改订单的状态
     * @param orderVO
     */
//    @Update("update orders set status = #{status} where id = #{id}")
    void update(OrderVO orderVO);


    /**
     * 查询所有数据
     * @param ordersPageQueryDTO
     * @return
     */
    Page<OrderVO> selectAll(OrdersPageQueryDTO ordersPageQueryDTO);

    /**
     * 计数
     * @param status
     * @return
     */
    @Select("select count(status) from orders where status = #{status}")
    Integer countStatus(Integer status);

@Update("update orders set status = #{status} where id = #{id}")
    void updateStatus(OrdersDTO ordersDTO);

    /**
     * 根据订单状态查询所有
     * @param status
     */
    @Select("select * from orders where status = #{status} and order_time  < #{time}")
    List<Orders> selectByStatus(Integer status, LocalDateTime time);

    /**
     * 根据订单号和用户ID查询
     * @param outTradeNo
     * @param userId
     * @return
     */
    @Select("select * from orders where number = #{outTradeNo} and user_id = #{userId}")
    Orders getByNumberAndUserId(String outTradeNo, Long userId);
@Update("update orders set pay_method = #{payMethod},status =#{status},pay_status = #{payStatus}  where number = #{number}")
    void updateByNumber(OrderVO orderVO);
}
